﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace underwater
{
    
    class Cursor//курсор
    {
        public static Rectangle cursorPosition;
        bool isRun;
        int Hframe = 25,
            Wframe = 26;
        int Frames = Loader.Textures[TextureEnum.Cursor].Width / 26;
        int currentFrame;
        int timeElapsed;
        int timeForFrame = 60;
        MouseState mouse1;
        public void Update(GameTime time)
        {
            MouseState mouse = Mouse.GetState();
            cursorPosition = new Rectangle(mouse.X, mouse.Y,(int)(Wframe*1.5),(int)(Hframe*1.5));            
                timeElapsed += time.ElapsedGameTime.Milliseconds;
                if (timeElapsed > timeForFrame)
                {
                    currentFrame = (currentFrame + 1) % Frames;
                    timeElapsed = 0;
                }
                if (mouse.X < mouse1.X)                
                    isRun = false;                
                if (mouse.X > mouse1.X)                
                    isRun = true;
            mouse1 = Mouse.GetState();
        }
        public void Draw(SpriteBatch spritebatch)
        {
            Rectangle r = new Rectangle(currentFrame * Wframe, 0, Wframe, Hframe);
            spritebatch.Begin();
          
            
                spritebatch.Draw(Loader.Textures[TextureEnum.Cursor], cursorPosition, r, Color.White, 0, Vector2.Zero, isRun ? SpriteEffects.FlipHorizontally : SpriteEffects.None, 0);
            
            
            spritebatch.End();
        }
    }
}
